/**
 * @Author wywinstonwy
 * @Date 2021/12/28 8:26 上午
 * @Description:
 */
import 'package:demo202112/utils/common_appbar.dart';
import 'package:demo202112/wy_container.dart';
import 'package:demo202112/wy_pageview1.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class WyDialog extends StatefulWidget {
  const WyDialog({Key? key}) : super(key: key);

  @override
  _WyDialogState createState() => _WyDialogState();
}

class _WyDialogState extends State<WyDialog> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar("Dialog"),
      body: ListView(
        children: [
          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _baseDialog();
                },
                child: Text('弹框')),
          ),
          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _baseDialogiOS();
                },
                child: Text('弹框ios风格')),
          ),

          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _styledialog();
                },
                child: Text('弹框自定义风格')),
          ),
          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _baseValueDialogiOS();
                },
                child: Text('弹框按钮返回值')),
          ),
          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _simpleDialogiOS();
                },
                child: Text('simpledialog')),
          ),
          Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _bugDialogiOS();
                },
                child: Text('大招diolog')),
          ),Container(
            margin: EdgeInsets.all(20),
            child: ElevatedButton(
                onPressed: () {
                  _loadingDialogiOS();
                },
                child: Text('进度加载显示框')),
          ),
        ],
      ),
    );
  }

  _baseDialog() {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('标题'),
            content: Text('这里可以写描述相关提示信息'),
            actions: [ TextButton(child: Text('取消'),onPressed: (){},),
              TextButton(child: Text('确认'),onPressed: (){},),],
          );
        });
  }
  _baseDialogiOS() {
    showCupertinoDialog(
        context: context,
        barrierDismissible: true,
        builder: (context) {
          return CupertinoAlertDialog(
            title: Text('标题'),
            content: Text('这里可以写描述相关提示信息'),
            actions: [ TextButton(child: Text('取消'),onPressed: (){
              Navigator.pop(context);
            },),
              TextButton(child: Text('确认'),onPressed: (){},),],
          );
        });
  }
  _styledialog(){
    showDialog(context: context, builder: (context){
      return AlertDialog(
        title: Text('提示'),
        content: Text('确认删除吗？'),
        backgroundColor: Colors.green,
        elevation: 24,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
        actions: <Widget>[
          FlatButton(child: Text('取消'),onPressed: (){},),
          FlatButton(child: Text('确认'),onPressed: (){},),
        ],
      );
    });
  }
  _baseValueDialogiOS() async{
    var result = await showCupertinoDialog(
        context: context,
        barrierDismissible: true,
        builder: (context) {
          return CupertinoAlertDialog(
            title: Text('标题'),
            content: Text('这里可以写描述相关提示信息'),
            actions: [ TextButton(child: Text('取消'),onPressed: (){
              Navigator.of(context).pop('cancel');
            },),
              TextButton(child: Text('确认'),onPressed: (){
                Navigator.of(context).pop('ok');

              },),],
          );
        });
    print(result);
  }
  _simpleDialogiOS() async{
    var result = await showCupertinoDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text('标题',textAlign: TextAlign.center,),
            children: [
              Container(height: 80,
                alignment: Alignment.center,
                child: Text('你确认要删除吗？？》'),
              ),
              TextButton(child: Text('取消'),onPressed: (){
                Navigator.of(context).pop('cancel');
              },),
              TextButton(child: Text('确认'),onPressed: (){
                Navigator.of(context).pop('ok');

              },),
            ],
          );
        });
    print(result);
  }
  _bugDialogiOS() async{
    var result = await showCupertinoDialog(
        context: context,
        builder: (context) {
          return Dialog(
            child: WyContainer(),

          );
        });
    print(result);
  }
  _loadingDialogiOS() async{
    var result = await showCupertinoDialog(
        context: context,
        builder: (context) {
          return Dialog(
            child: Container(
              
              height: 300,
              width: 100,
              child: Container(
                padding: EdgeInsets.all(40),
                child: CircularProgressIndicator(),
              ),
            ),

          );
        });
    print(result);
  }
  _buildLoading(){
    // final DialogTheme dialogTheme = DialogTheme.of(context);
    // return AnimatedPadding(
    //   padding: MediaQuery.of(context).viewInsets + const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
    //   duration: insetAnimationDuration,
    //   curve: insetAnimationCurve,
    //   child: MediaQuery.removeViewInsets(
    //     removeLeft: true,
    //     removeTop: true,
    //     removeRight: true,
    //     removeBottom: true,
    //     context: context,
    //     //所以我们其实只需要修改child这个属性了，改成我们想要展示的widget就行了。
    //     child: Center(
    //       child: ConstrainedBox(
    //         constraints: const BoxConstraints(minWidth: 280.0),
    //         child: Material(
    //           elevation: 24.0,
    //           color: Colors.blue,
    //           type: MaterialType.card,
    //           child: child,
    //           shape: shape ?? dialogTheme.shape ?? _defaultDialogShape,
    //         ),
    //       ),
    //     ),
    //   ),
    // );
  }
}
